﻿/************************************************
 * Copyright (C) 2011 东北农业大学(NEAU)
 * 版权所有。
 * 文件名：StockRoomRegister.aspx.cs
 * 版本号：v1.0
 * 文件功能描述：仓库入库登记添加
 * 作者：侯建
 * 创建日期：2011.04.14
************************************************/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using System.Reflection;
using System.Data.SqlClient;

namespace Jxym.wlkc2011.Module.Default.server.StockRoom
{
    public partial class InStockRoom : System.Web.UI.Page
    {
        int id = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                MsSqlDal<model.StockRoom> iUi = new MsSqlDal<model.StockRoom>();
                PropertyInfo[] fields = typeof(model.StockRoom).GetProperties();
                List<string> listName = new List<string>();
                List<string> listValue = new List<string>();

                object identity = 0;
                int modelid = 0;

                if (Request.Params["modelid"] != null) modelid = Convert.ToInt32(Request.Params["modelid"]);

                string returnStr = "{'success':false,'msg':'参数错误'}";

                foreach (PropertyInfo property in fields)
                {
                    if (Request.Params[property.Name] != null)
                    {
                        listName.Add("@" + property.Name);
                        listValue.Add(Request.Params[property.Name]);
                    }
                }

                SqlParameter[] parameters = new SqlParameter[listName.Count];

                for (int i = 0; i < listName.Count; i++)
                {
                    parameters[i] = new SqlParameter(listName[i], listValue[i]);
                }

                if (Request.Params["ID"] != null && !Request.Params["ID"].Equals(""))
                {
                    id = Convert.ToInt32(Request.Params["ID"]);
                }

                if (id < 0)
                {
                    Response.Write(returnStr);
                    return;
                }

                if (id > 0)
                {
                    //判断该通知发布人是不是当前用户
                    if (MyGet.GetPermissionsValidation(modelid, "U", Jxym.Common.Request.AdminID("user")))
                    {
                        identity = iUi.Updata("ID = " + id, parameters);
                        returnStr = "{'success':true,'msg':'更新完成'}";
                    }
                    else
                    {
                        returnStr = "{'success':false,'msg':'对不起，您没有编辑权限'}";
                    }
                }
                else
                {
                    if (MyGet.GetPermissionsValidation(modelid, "A", Jxym.Common.Request.AdminID("user")))
                    {
                        identity = iUi.Add(parameters);
                        returnStr = "{'success':true,'msg':'申请完成'}";
                    }
                    else
                    {
                        returnStr = "{'success':false,'msg':'对不起，您没有入库权限'}";
                    }
                }
                Response.Write(returnStr);
            }
        }
    }
}